<?php


namespace app\api\controller;


use logicmodel\BoxLogic;
use logicmodel\GoodsLogic;
use logicmodel\TradeLogic;
use think\Request;

class Orders extends BaseController
{
    private $goodsLogic;
    private $boxLogic;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->goodsLogic = new GoodsLogic();
        $this->boxLogic = new BoxLogic();
    }

    /**
     * NFT购买
     * @param $id
     * @param int $pay_type
     * @return \think\response\Json
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function goodsApply($id,$pay_type=1){
        return json($this->goodsLogic->apply($this->userInfo,$id,$pay_type));
    }

    /**
     * 购买盲盒
     * @param $id
     * @param int $pay_type
     * @return \think\response\Json
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function boxApply($id,$pay_type=1){
        return json($this->boxLogic->apply($this->userInfo,$id,$pay_type));
    }

    /**
     * 会员作品列表
     * @param int $status
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function usersGoodsList($status=1){
        return json($this->goodsLogic->usersGoodsList($this->uid,$status));
    }

    /**
     * 会员NFT作品详情
     * @param $id
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function usersGoodsDetail($id){
        return json($this->goodsLogic->usersGoodsDetail($this->uid,$id));
    }
    /**
     * 作品出售
     * @param $id
     * @param $price
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function goodsSale($id,$price){
        return json($this->goodsLogic->sale($this->uid,$id,$price));
    }

    /**
     * 商品转赠
     * @param $id
     * @param $phone
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function goodsTransfer($id,$phone){
        return json($this->goodsLogic->transfer($this->uid,$id,$phone));
    }

    /**
     *修改作品价格
     * @param $id
     * @param $price
     * @return \think\response\Json
     */
    public function goodsUpdatePrice($id,$price){
        return json($this->goodsLogic->updatePrice($this->uid,$id,$price));
    }
    /**
     *切换展示状态
     * @param $id
     * @param $is_show
     * @return \think\response\Json
     */
    public function goodsUpdateShow($id,$is_show){
        return json($this->goodsLogic->updateShow($this->uid,$id,$is_show));
    }
    /**
     * 盲盒出售
     * @param $id
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function boxSale($id,$price){
        return json($this->boxLogic->sale($this->uid,$id,$price));
    }


    /**
     * 修改盲盒价格
     * @param $id
     * @param $price
     * @return \think\response\Json
     */
    public function boxUpdatePrice($id,$price){
        return json($this->boxLogic->updatePrice($this->uid,$id,$price));
    }

    /**
     * 切换盲盒状态
     * @param $id
     * @param $is_show
     * @return \think\response\Json
     */
    public function boxUpdateShow($id,$is_show){
        return json($this->boxLogic->updateShow($this->uid,$id,$is_show));
    }

    /**
     * 打开盲盒
     * @param $id
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function boxOpen($id){
        return json($this->boxLogic->open($this->uid,$id));
    }

    /**
     * 会员盲盒列表
     * @param int $status
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function usersBoxList($status=1){
        return json($this->boxLogic->usersBoxList($this->uid,$status));
    }
    /**
     * 会员盲盒详情
     * @param $id
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function userBoxDetail($id){
        return json($this->boxLogic->userBoxDetail($this->uid,$id));
    }

    /**
     * 市场NFT交易
     * @param $users_goods_id
     * @param int $pay_type
     * @return \think\response\Json
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function tradeGoods($users_goods_id,$pay_type=1){
        return json((new TradeLogic())->tradeGoods($this->userInfo,$users_goods_id,$pay_type));
    }

    /**
     * 市场盲盒交易
     * @param $users_box_id
     * @param int $pay_type
     * @return \think\response\Json
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function tradeBox($users_box_id,$pay_type=1){
        return json((new TradeLogic())->tradeBox($this->userInfo,$users_box_id,$pay_type));
    }
}